<?php
/**
 * Created by IntelliJ IDEA.
 * User: ahwwl
 * Date: 18-8-3
 * Time: 下午4:55
 */

namespace app\controller;


use app\model\AgentList;
use app\model\ApplyIdList;
use app\model\ApplyList;
use app\model\CompanyList;
use app\model\OrderList;
use app\model\UserCardList;
use app\model\WalletLog;
use commen\ebjyd;
use think\Db;
use think\Exception;
use think\Request;

/**
 * @property AgentList AgentList
 * @property CompanyList CompanyList
 * @property UserCardList UserCardList
 * @property ApplyIdList ApplyIdList
 * @property ApplyList ApplyList
 * @property OrderList OrderList
 * @property WalletLog WalletLog
 */
class Companys extends CommonController
{
    function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->AgentList = new AgentList();
        $this->CompanyList = new CompanyList();
        $this->UserCardList = new UserCardList();
        $this->ApplyIdList = new ApplyIdList();
        $this->ApplyList = new ApplyList();
        $this->OrderList = new OrderList();
        $this->WalletLog = new WalletLog();
    }

    function company_list()
    {
        try {
            $agent_list = $this->AgentList->field("id,agent_name")->select();
            $this->assign("agent_list",$agent_list);

        }catch (Exception $e) {
        }

        $this->assign("page_title", "企业列表");
        return $this->fetch();
    }
    function ajax_company_list()
    {
        try
        {
            $page = input("page",1,"intval");
            $rows = input("rows",30,"intval");
            $agent_id = input("agent_id",0,"intval");
            $name = input("name","","trim");
            $card_id = input("card_id","","trim");

            $status = input("status",-1,"intval");
            $where = [];
            if(in_array($status,[0,1]))
                $where["cl.status"] = $status;
            if(!empty($agent_id))
                $where["agent_id"] = $agent_id;
            if(!empty($name))
                $where["name"] = ["like","%".$name."%"];
            if(!empty($card_id))
                $where["card_id"] = ["like","%".$card_id."%"];
            $count = $this->CompanyList->alias("cl")
                ->where($where)
                ->count();
            $page_total = ceil($count/$rows);
            $page = $page>$page_total?$page_total:$page;
            $page = $page < 1? 1:$page;
            $order_log = $this->CompanyList->alias("cl")
                ->join("f_agent_list al","al.id=cl.agent_id","left")
                ->where($where)
                ->field("cl.*,al.agent_name")
                ->order("cl.ctime desc")
                ->limit(($page-1)*$rows,$rows)
                ->select();


            $this->resultdata["data"] = $order_log;
            $this->resultdata["error"] = 0;
            $this->resultdata["total"] = $count;
            $this->resultdata["page"] = $page;
            $this->resultdata["rows"] = $rows;
        }catch (\Exception $e)
        {

            $this->resultdata["msg"] = $e->getMessage();
        }
        $this->ajaxResult();
    }
    function ajax_company_info()
    {
        try
        {
            $id = input("id",0,"intval");
            if(empty($id))
                $this->E("参数不能为空");
            $info = $this->CompanyList
                ->where(["id"=>$id])->find();
            if(empty($info))
                \exception("信息不存在");
            $info["discount"] =number_format($info["discount"]/10000, 2, '.', '');
            $info["rebate_discount"] =number_format($info["rebate_discount"]/10000, 2, '.', '');

            $this->resultdata["data"] = $info;
            $this->resultdata["error"] = 0;
        }catch (\Exception $e)
        {
            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }
    function ajax_company_info_save()
    {
        try
        {
            $id = input("id",0,"intval");
            $agent_id = input("agent_id",0,"intval");
            $discount = input("discount",0,"floatval");
            $rebate_discount = input("rebate_discount",0,"floatval");
            $name = input("name","","trim");
            $real_name = input("real_name","","trim");
            $mobile = input("mobile","","trim");
            $adress = input("adress","","trim");
            $legal_name = input("legal_name","","trim");
            $legal_id_card = input("legal_id_card","","trim");
            $business_no = input("business_no","","trim");
            $billing_no = input("billing_no","","trim");
            $status = input("status",0,"intval");
            if(!in_array($status,[0,1])||empty($discount)||empty($name)||empty($real_name)||empty($mobile)
                ||empty($adress)||empty($legal_name)||empty($legal_id_card)||empty($business_no)||empty($billing_no))
                $this->E("参数不正确");
            if(!empty($agent_id))
            {
                $agent_info = $this->AgentList->where(["id"=>$agent_id])->field("id,agent_name")->find();
                if(empty($agent_info))
                    \exception("代理不存在");
            }
            $discount = $discount*10000;
            $rebate_discount = $rebate_discount*10000;
            $info = [
                "agent_id"=>$agent_id,
                "discount"=>$discount,
                "rebate_discount" =>$rebate_discount,
                "name" =>$name,
                "real_name" =>$real_name,
                "mobile" =>$mobile,
                "adress" =>$adress,
                "legal_name" =>$legal_name,
                "legal_id_card" =>$legal_id_card,
                "business_no" =>$business_no,
                "billing_no" =>$billing_no,
                "status"=>$status,
                "mtime"=>NOW_TIME
            ];
            if($id)
            {
                $query = $this->CompanyList->where(["id"=>$id])->update($info);
                if(empty($query))
                {
                    $this->E("更新失败");
                }
            }else{
                $info["ctime"] = NOW_TIME;
                $id = $this->CompanyList->insertGetId($info);
                if(empty($id))
                {
                    $this->E("添加失败");
                }
            }
            $this->resultdata["error"] = 0;
        }catch (\Exception $e)
        {
            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }
    function ajax_company_set_credit()
    {
        try
        {
            $id = input("id",0,"intval");
            $credit = input("credit",0,"intval");
            if(empty($id)||empty($credit))
                $this->E("参数不正确");
            $credit = $credit*10000;
            $query = $this->CompanyList->where(["id"=>$id])->setInc("credit",$credit);
            if(empty($query))
            {
                $this->E("更新失败");
            }
            $this->resultdata["error"] = 0;
        }catch (\Exception $e)
        {
            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }
    function ajax_company_set_balance()
    {
        try
        {
            $id = input("id",0,"intval");
            $balance = input("balance",0,"intval");
            if(empty($id)||empty($balance))
                $this->E("参数不正确");
            $balance = $balance*10000;

            Db::startTrans();
            try{
                $query = $this->CompanyList->where(["id"=>$id])->setInc("balance",$balance);
                if(empty($query))
                {
                    $this->E("更新失败");
                }
                $wallet_info = [
                    "company_id"=>$id,
                    "type"=>5,
                    "money"=>$balance,
                    "info"=>"加款：".($balance/10000),
                    "ctime"=>NOW_TIME

                ];
                $query = $this->WalletLog->insert($wallet_info);
                if(empty($query))
                {

                    $this->E("流水添加失败");
                }
                Db::commit();
            }catch (\Exception $e)
            {
                Db::rollback();
                $this->E($e->getMessage());
            }
            $this->resultdata["error"] = 0;
        }catch (\Exception $e)
        {
            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }

    function card_list()
    {
        try {
            $agent_list = $this->AgentList->field("id,agent_name")->select();
            $company_list = $this->CompanyList->field("id,name")->select();
            $this->assign("agent_list",$agent_list);
            $this->assign("company_list",$company_list);

        }catch (Exception $e) {
        }

        $this->assign("page_title", "企业柴油卡列表");
        return $this->fetch();
    }
    function ajax_card_list()
    {
        try
        {
            $page = input("page",1,"intval");
            $rows = input("rows",30,"intval");
            $card_no = input("card_no","","trim");
            $status = input("status",0,"intval");
            $agent_id = input("agent_id",0,"intval");
            $company_id = input("company_id",0,"intval");

            $where = [];
            if(!empty($card_no))
                $where["ucl.card_no"] = ["like","%".$card_no."%"];
            if($status !=-1)
                $where["ucl.status"] = $status;
            if(!empty($agent_id))
                $where["ucl.agent_id"] = $agent_id;
            if(!empty($company_id))
                $where["ucl.company_id"] = $company_id;
            $where["ucl.card_type"] = ["in",[2]];

            $count = $this->UserCardList->alias("ucl")
                ->where($where)
                ->count();
            $page_total = ceil($count/$rows);
            $page = $page>$page_total?$page_total:$page;
            $page = $page < 1? 1:$page;
            $order_log = $this->UserCardList->alias("ucl")
                ->join("f_company_list cl","cl.id=ucl.company_id","left")
                ->join("f_agent_list al","al.id=cl.agent_id","left")
                ->where($where)
                ->field("ucl.*,cl.name,al.agent_name")
                ->order("ucl.id desc")
                ->limit(($page-1)*$rows,$rows)
                ->select();


            $this->resultdata["data"] = $order_log;
            $this->resultdata["error"] = 0;
            $this->resultdata["total"] = $count;
            $this->resultdata["page"] = $page;
            $this->resultdata["rows"] = $rows;
        }catch (\Exception $e)
        {

            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }
    function ajax_add_order()
    {
        try {


            $row_list = input("row_list/a", []);
            $amount = input("amount",0,"intval");
            $is_pay = input("is_pay",0,"intval");

            if (empty($row_list) ||empty($amount)) {
                $this->E("参数不正确");
            }
            $amount = $amount*10000;
            $list = make_array($row_list,"card_no");
            if (empty($list) ) {
                $this->E("参数不正确");
            }


            $CardListInfo = $this->UserCardList->where(['card_no' => ["in",$list],"company_id" =>["GT",0],"card_type"=>2,"status"=>1])->select();
            $card_lists = make_array($CardListInfo,"card_no");
            $company_ids = make_array($CardListInfo,"company_id");
            if(count($list) != count($card_lists))
            {
                $this->E("不存在卡号：".json_encode(array_diff($card_lists,$list)));
            }
            $company_list = $this->CompanyList->where(['id' => ["in",$company_ids],"status"=>0])->select();
            $company_list = make_array_key($company_list,"id",true);
            $order_info_list = [];
            $wallet_info_list = [];
            $total_money_list = [];
            foreach ($CardListInfo as $card_info)
            {
                $card_no = $card_info["card_no"];
                $card_type = $card_info["card_type"];
                $company_id = $card_info["company_id"];
                if(empty($company_list[$company_id]))
                    \exception("企业不存在");
                $company_info = $company_list[$company_id];
                $agent_id = $company_info["agent_id"];
                $discount= $company_info["discount"];
                $balance = $company_info["balance"];
                $credit = $company_info["credit"];
                $basic_price = $amount;
                $cost = $basic_price*COST_DISCOUNT;
                $money = $basic_price*$discount/10000;
                $ip = $this->request->ip();
                $order_info = $this->OrderList->addCompanyCardOrder($agent_id,$company_id,$card_no,$card_type,$basic_price,$cost,$money,0,$money,$ip);
                $order_no = $order_info["order_no"];
                if($is_pay == 1)
                {

                    if(($balance+$credit)<$money)
                        \exception("企业预存款不足:".$company_id);
                    $company_list[$company_id]["balance"] -= $money;
                    $order_info["pay_status"] = 1;
                    $wallet_info = [
                        "company_id" =>$company_id,
                        "type" =>4,
                        "order_no" =>$order_no,
                        "money" =>-$money,
                        "info"=>"卡充值",
                        "ctime"=>NOW_TIME,
                    ];
                    $wallet_info_list[] = $wallet_info;
                }
                $order_info_list[] = $order_info;
                if(empty($total_money_list[$company_id]))
                    $total_money_list[$company_id] = 0;
                $total_money_list[$company_id] +=$money;
            }

            Db::startTrans();
            try{
                if($is_pay == 1)
                {
                    foreach ($total_money_list as $key=>$value)
                    {
                        $query = $this->CompanyList->where(["id"=>$key])->where("(balance+credit)>=".$value)
                            ->setDec("balance", $value);
                        if(!$query)
                            \exception("企业余额不足");
                    }
                }
                $query = $this->OrderList->insertAll($order_info_list);
                if(empty($query))
                {
                    exception("提交订单添加失败");
                }
                if($wallet_info_list)
                {
                    $query = $this->WalletLog->insertAll($wallet_info_list);
                    if(empty($query))
                    {
                        exception("订单消费记录添加失败");
                    }
                }


                Db::commit();
            }catch (\Exception $e)
            {
                Db::rollback();
                \exception($e->getMessage());
            }
            $this->resultdata["error"] = 0;
        } catch (\Exception $e) {
            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }

    function apply_id_list()
    {
        try {
            $agent_list = $this->AgentList->field("id,agent_name")->select();
            $company_list = $this->CompanyList->field("id,name")->select();
            $this->assign("agent_list",$agent_list);
            $this->assign("company_list",$company_list);

        }catch (Exception $e) {
        }

        $this->assign("page_title", "申请审核证明列表");
        return $this->fetch();
    }
    function ajax_apply_id_list()
    {
        try
        {
            $page = input("page",1,"intval");
            $rows = input("rows",30,"intval");
            $cert_no = input("cert_no","","trim");
            $status = input("status",0,"intval");


            $where = [];
            if(!empty($cert_no))
                $where["cert_no"] = ["like","%".$cert_no."%"];
            if($status !=-1)
                $where["status"] = $status;


            $count = $this->ApplyIdList
                ->where($where)
                ->count();
            $page_total = ceil($count/$rows);
            $page = $page>$page_total?$page_total:$page;
            $page = $page < 1? 1:$page;
            $order_log = $this->ApplyIdList
                ->where($where)
                ->order("id desc")
                ->limit(($page-1)*$rows,$rows)
                ->select();


            $this->resultdata["data"] = $order_log;
            $this->resultdata["error"] = 0;
            $this->resultdata["total"] = $count;
            $this->resultdata["page"] = $page;
            $this->resultdata["rows"] = $rows;
        }catch (\Exception $e)
        {

            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }

    function ajax_apply_id_save()
    {
        try
        {
            $id = input("id",0,"intval");
            $provider = input("provider","","trim");

            $cert_no = input("cert_no","","trim");

            $approvalImg = input("approvalImg","","trim");
            $remark = input("remark","","trim");
            $type = input("type",2,"intval");
            if(!in_array($type,[1,2])||empty($provider)||empty($cert_no)||empty($approvalImg))
                $this->E("参数不正确");
            $filename1 = UPLOAD_PATH.$approvalImg;
            $fileinfo=pathinfo($filename1);
            $basename = $fileinfo["basename"];
            $path =  "/apply_id_list/$basename";
            $filename2 = UPLOAD_PATH.$path;
            if($filename1 == $filename2)
                \exception("文件一样，不能上传");
            if(!is_file($filename1))
                exception("文件不存在");
            $result = copy($filename1, $filename2);
            if(!$result)
            {
//                    unlink($filename2);
                exception("复制文件错误");
            }

            $info = [
                "provider"=>$provider,
                "cert_no"=>$cert_no,
                "approvalImg" =>$path,
                "remark" =>$remark,
                "type" =>$type,
                "mtime"=>NOW_TIME
            ];
            if($id)
            {
                $query = $this->ApplyIdList->where(["id"=>$id])->update($info);
                if(empty($query))
                {
                    $this->E("更新失败");
                }
            }else{
                $info["ctime"] = NOW_TIME;
                $id = $this->ApplyIdList->insertGetId($info);
                if(empty($id))
                {
                    $this->E("添加失败");
                }
            }
            $this->resultdata["error"] = 0;
        }catch (\Exception $e)
        {
            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }
    function ajax_apply_id_submit()
    {
        try
        {
            $id = input("id",0,"intval");

            if(empty($id))
                \exception("参数不正确");

            $info = $this->ApplyIdList->where(["id"=>$id])->find();
            if(empty($info))
            {
                \exception("该记录不存在");
            }
            if($info["status"] !=0)
            {
                \exception("数据已经提交");
            }
            $query = $this->ApplyIdList->where(["id"=>$id,"status"=>0])->update(["status"=>1]);
            if(empty($query))
                exception("已经提交");
            $cert_no = $info["cert_no"];
            $type = $info["type"];
            $provider = $info["provider"];
            $approvalImg = !empty($info["approvalImg"])?base64EncodeImage(UPLOAD_PATH.$info["approvalImg"]):"";

            $result = ebjyd::applyDiesel($provider,$cert_no,$type,$approvalImg);
            if($result["error"] == 0)
            {
                $query = $this->ApplyIdList->where(["id"=>$id,"status"=>1])->update(["status"=>2,"approval_id"=>$result["data"]]);
                if(empty($query))
                    exception("已经提交更新失败");
            }else{
                exception("提交失败:".$result["raw_post_data"]);
            }
            $this->resultdata["error"] = 0;
        }catch (\Exception $e)
        {
            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }
    function apply_list()
    {
        try {
            $apply_id_list = $this->ApplyIdList->where(["status"=>2])->field("id,provider,approval_id,approvalImg")->order("id desc")->select();
            $company_list = $this->CompanyList->field("id,name")->select();
            $agent_list = $this->AgentList->field("id,agent_name")->select();
            $this->assign("apply_id_list",$apply_id_list);
            $this->assign("company_list",$company_list);
            $this->assign("agent_list",$agent_list);
        }catch (Exception $e) {
        }

        $this->assign("page_title", "柴油卡申请列表");
        return $this->fetch();

    }
    function ajax_apply_list()
    {
        try
        {
            $page = input("page",1,"intval");
            $rows = input("rows",30,"intval");
            $card_no = input("card_no","","trim");
            $card_id = input("card_id","","trim");
            $status = input("status",0,"intval");
            $agent_id = input("agent_id",0,"intval");
            $company_id = input("company_id",0,"intval");

            $where = [];
            if(!empty($card_no))
                $where["fal.card_no"] = ["like","%".$card_no."%"];
            if(!empty($card_id))
                $where["fal.card_id"] = ["like","%".$card_id."%"];
            if($status !=-1)
                $where["fal.status"] = $status;
            if(!empty($agent_id))
                $where["cl.agent_id"] = $agent_id;
            if(!empty($company_id))
                $where["fal.company_id"] = $company_id;

            $count = $this->ApplyList->alias("fal")
                ->join("f_company_list cl","cl.id=fal.company_id","left")
                ->join("f_agent_list al","al.id=cl.agent_id","left")
                ->where($where)
                ->count();
            $page_total = ceil($count/$rows);
            $page = $page>$page_total?$page_total:$page;
            $page = $page < 1? 1:$page;
            $order_log = $this->ApplyList->alias("fal")
                ->join("f_company_list cl","cl.id=fal.company_id","left")
                ->join("f_agent_list al","al.id=cl.agent_id","left")
                ->where($where)
                ->field("fal.*,cl.name,al.agent_name")
                ->order("fal.id desc")
                ->limit(($page-1)*$rows,$rows)
                ->select();


            $this->resultdata["data"] = $order_log;
            $this->resultdata["error"] = 0;
            $this->resultdata["total"] = $count;
            $this->resultdata["page"] = $page;
            $this->resultdata["rows"] = $rows;
        }catch (\Exception $e)
        {

            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }
    function ajax_apply_save()
    {
        try
        {
            $id = input("id",0,"intval");
            $company_id = input("company_id",0,"intval");

            $card_id = input("card_id","","trim");
            $plate_number = input("plate_number","","trim");
            $card_img_url_1 = input("card_img_url_1","","trim");
            $card_img_url_2 = input("card_img_url_2","","trim");
            $driving_img_url_1 = input("driving_img_url_1","","trim");

            $driving_img_url_2 = input("driving_img_url_2","","trim");
            if(empty($company_id)||empty($card_id)||empty($plate_number)||empty($card_img_url_1)||empty($card_img_url_2)||empty($driving_img_url_1)
                ||empty($driving_img_url_2))
                \exception("参数不正确");


            $info = [
                "company_id"=>$company_id,
                "card_id"=>$card_id,
                "plate_number" =>$plate_number,
                "card_img_url_1" =>$card_img_url_1,
                "card_img_url_2" =>$card_img_url_2,
                "driving_img_url_1" =>$driving_img_url_1,
                "driving_img_url_2" =>$driving_img_url_2,
                "mtime"=>NOW_TIME
            ];
            $list = ["card_img_url_1","card_img_url_2","driving_img_url_1","driving_img_url_2"];
            foreach($list as $key)
            {
                $filename1 = UPLOAD_PATH.$info[$key];
                $fileinfo=pathinfo($filename1);
                $basename = $fileinfo["basename"];
                $path =  "/apply_id_list/$basename";
                $filename2 = UPLOAD_PATH.$path;
                if($filename1 == $filename2)
                    \exception("文件一样，不能上传");
                if(!is_file($filename1))
                    exception("文件不存在");
                $result = copy($filename1, $filename2);
                if(!$result)
                {
//                    unlink($filename2);
                    exception("复制文件错误");
                }
            }

            if($id)
            {
                $query = $this->ApplyList->where(["id"=>$id])->update($info);
                if(empty($query))
                {
                    $this->E("更新失败");
                }
            }else{
                $info["ctime"] = NOW_TIME;
                $id = $this->ApplyList->insertGetId($info);
                if(empty($id))
                {
                    $this->E("添加失败");
                }
            }
            $this->resultdata["error"] = 0;
        }catch (\Exception $e)
        {
            $this->resultdata["msg"] = $e->getMessage();
        }
        $this->ajaxResult();
    }
    function ajax_add_approval_id()
    {
        try
        {
            $id = input("id",0,"intval");

            $approval_id = input("approval_id","","trim");

            if(empty($id)||empty($approval_id))
                \exception("参数不正确");
            $info = [
                "approval_id"=>$approval_id,
                "mtime"=>NOW_TIME
            ];
            $query = $this->ApplyList->where(["id"=>$id])->update($info);
            if(empty($query))
            {
                \exception("更新失败");
            }
            $this->resultdata["error"] = 0;
        }catch (\Exception $e)
        {
            $this->resultdata["msg"] = $e->getMessage();
        }
        $this->ajaxResult();
    }
    function ajax_apply_submit()
    {
        try
        {
            $id = input("id",0,"intval");

            if(empty($id))
                \exception("参数不正确");

            $info = $this->ApplyList->where(["id"=>$id])->find();
            if(empty($info))
            {
                \exception("该记录不存在");
            }
            if($info["status"] !=0)
            {
                \exception("数据已经提交");
            }
            $query = $this->ApplyList->where(["id"=>$id,"status"=>0])->update(["status"=>1]);
            if(empty($query))
                exception("已经提交");
            $plate_number = $info["plate_number"];
            $card_img_url_1 = !empty($info["card_img_url_1"])?base64EncodeImage(UPLOAD_PATH.$info["card_img_url_1"]):"";
            $card_img_url_2 = !empty($info["card_img_url_2"])?base64EncodeImage(UPLOAD_PATH.$info["card_img_url_2"]):"";
            $driving_img_url_1 = !empty($info["driving_img_url_1"])?base64EncodeImage(UPLOAD_PATH.$info["driving_img_url_1"]):"";
            $driving_img_url_2 = !empty($info["driving_img_url_2"])?base64EncodeImage(UPLOAD_PATH.$info["driving_img_url_2"]):"";
            $approval_id = $info["approval_id"];
            $notifyURL = $this->host."/notify/applyDieseCallback";
            $result = ebjyd::apply($plate_number,"18512520188",$card_img_url_1,$card_img_url_2,$driving_img_url_1,$driving_img_url_2,$approval_id,$notifyURL);
            if($result["error"] == 0)
            {
                $this->ApplyList->where(["id"=>$id,"status"=>1])->update(["raw_post_data"=>$result["raw_post_data"]]);
            }else{
                $query = $this->ApplyList->where(["id"=>$id,"status"=>1])->update(["status"=>3,"raw_post_data"=>$result["raw_post_data"]]);
                if(empty($query))
                    exception("提交失败更新失败");
                exception("提交失败:".$result["raw_post_data"]);
            }
            $this->resultdata["error"] = 0;
        }catch (\Exception $e)
        {
            $this->resultdata["msg"] = $e->getMessage();
        }

        echo json_encode($this->resultdata);
    }


}